/*

* ------------------------------------------------------------------------
* ------------------------------------------------------------------------
* |     Smart-Shop开源商城系统/ Java商城-首选电商平台系统 请务必保留此注释头信息
* |     开源地址: https://gitee.com/ningbo-qishan/gruul-mall
* ------------------------------------------------------------------------
* ------------------------------------------------------------------------
* |     可正常分享和学习源码,未经授权 不可商用！
* |     商业版中台购买/开源版商业授权 联系技术客服
* |     官网:  https://www.73app.cn/
* ------------------------------------------------------------------------
* ------------------------------------------------------------------------
* |     Copyright (c) 2016-2999 宁波启山智软科技有限公司
* |     版权所有 ,侵权必究！
* ------------------------------------------------------------------------

*/
package com.medusa.gruul.recycling.web.controller;


import com.medusa.gruul.common.core.util.Result;
import com.medusa.gruul.common.core.util.ResultPageList;
import com.medusa.gruul.recycling.model.dto.RecyclingOrderNewDto;
import com.medusa.gruul.recycling.model.dto.RecyclingOrderSendDto;
import com.medusa.gruul.recycling.model.vo.RecyclingOrderListVo;
import com.medusa.gruul.recycling.model.vo.RecyclingPcOrderListVo;
import com.medusa.gruul.recycling.service.IRecyclingOrderService;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

/**
 * <p>
 * 回收订单表 前端控制器
 * </p>
 *
 * @author whh
 * @since 2021-04-28
 */
@RestController
@RequestMapping("/recycling-order")
public class RecyclingOrderController {

    @Autowired
    private IRecyclingOrderService recyclingOrderService;


    @GetMapping("pc/list")
    @ApiOperation(value = "PC端商户获取相关订单", tags = "pc端-回收订单详情")
    public ResultPageList<RecyclingPcOrderListVo> recyclingPcOrderList(
            @ApiParam(value = "页数") @RequestParam Integer page,
            @ApiParam(value = "条数") @RequestParam Integer size,
            @ApiParam(value = "昵称") @RequestParam(required = false) String nickName,
            @ApiParam(value = "id") @RequestParam(required = false) Long id,
            @ApiParam(value = "物流单号") @RequestParam(required = false) String shipmentNumber
    ) {
        return recyclingOrderService.recyclingPcOrderList(page, size, nickName,id,shipmentNumber);
    }

    @GetMapping("exit/wait/send")
    @ApiOperation(value = "判断是否存在，需要寄出的回收订单,true 存在，false 不存在", tags = "小程序端-回收订单相关接口")
    public Result<Boolean> exitWaitSendOrder() {
        Boolean flag = recyclingOrderService.exitWaitSendOrder();
        return Result.ok(flag);
    }


    @PostMapping("new")
    @ApiOperation(value = "新增回收订单,返回当前订单获得的卡券", tags = "小程序端-回收订单相关接口")
    public Result recyclingOrderNew(@RequestBody @Validated RecyclingOrderNewDto dto) {
        String img = recyclingOrderService.recyclingOrderNew(dto);
        return Result.ok(img);
    }


    @GetMapping("list")
    @ApiOperation(value = "用户获取我的回收订单", tags = "小程序端-回收订单相关接口")
    public ResultPageList<RecyclingOrderListVo> recyclingOrderList(
            @ApiParam(value = "查询订单  0-全部  1-待寄出  2-已寄出  3-已取消") @RequestParam Integer orderStatus,
            @ApiParam(value = "页数") @RequestParam Integer page,
            @ApiParam(value = "条数") @RequestParam Integer size
    ) {
        return recyclingOrderService.recyclingOrderList(orderStatus, page, size);
    }

    @PutMapping("cancel/{id}")
    @ApiOperation(value = "用户取消新增的回收订单", tags = "小程序端-回收订单相关接口")
    public Result recyclingOrderCancel(
            @ApiParam(value = "订单id") @PathVariable(name = "id") Long id
    ) {
        recyclingOrderService.recyclingOrderCancel(id);
        return Result.ok();
    }

    @PutMapping("send")
    @ApiOperation(value = "用户寄出回收订单", tags = "小程序端-回收订单相关接口")
    public Result recyclingOrderSend(@RequestBody @Validated RecyclingOrderSendDto dto) {
        recyclingOrderService.recyclingOrderSend(dto);
        return Result.ok();
    }

    @DeleteMapping("del/{id}")
    @ApiOperation(value = "用户删除回收订单", tags = "小程序端-回收订单相关接口")
    public Result recyclingOrderDel(
            @ApiParam(value = "订单id") @PathVariable(name = "id") Long id
    ) {
        recyclingOrderService.recyclingOrderDel(id);
        return Result.ok();
    }
}
